package com.fjh.controller.bus;

import com.fjh.common.Result;
import com.fjh.domain.BusCustomer;
import com.fjh.dto.CustomDto;
import com.fjh.service.CustomService;
import com.fjh.vo.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/buscustom")
public class CustomController {

    @Autowired
    private CustomService customService;

    /**
     * 分页查询
     *
     * @param customDto
     * @return
     */
    @GetMapping("/findByPage.do")
    @RequiresPermissions("bus:custom:list")
    public Result findByPage(CustomDto customDto) {
        PageInfo<BusCustomer> byPage = customService.findByPage(customDto);
        return Result.ok(byPage);
    }

    /**
     * 新增数据
     *
     * @param customDto
     * @return
     */
    @PostMapping("/add.do")
    @RequiresPermissions("bus:custom:add")
    public Result add(@RequestBody CustomDto customDto) {
        Boolean isOk = customService.save(customDto);
        return isOk ? Result.ok() : Result.fail();
    }

    /**
     * 修改数据
     *
     * @param customDto
     * @return
     */
    @PostMapping("/update.do")
    @RequiresPermissions("bus:custom:update")
    public Result update(@RequestBody CustomDto customDto) {
        Boolean isOk = customService.updateById(customDto);
        return isOk ? Result.ok() : Result.fail();
    }

    /**
     * 删除数据
     *
     * @param ids
     * @return
     */
    @PostMapping("/delete.do/{ids}")
    @RequiresPermissions("bus:custom:delete")
    public Result delete(@PathVariable Integer[] ids) {
        Boolean isOk = customService.batchDelete(ids);
        return isOk ? Result.ok() : Result.fail();
    }
}
